javascript:(function (){
    var jca_title = 'FillCrew v3 by ★LOC@S★ נυαη ★L@★';
 html = '<ul style="margin: 0;padding: 0;width: 650px;">';
var before = true;
params = get_params();
if (params.show && params.show.indexOf('inside') != -1){
	var the_div = document.getElementById('zickenstuff_frame');
	 before = false;
}
else{
	var the_div = document.getElementById('quest');
}

  if (document.getElementById('juansinho_main') == undefined){
	  var the_area=document.createElement("div");
		var the_kick_button=document.createElement("a");		
		the_kick_button.className= 'sexy_button_new red short';
		the_kick_button.style.marginLeft='10px';
		the_kick_button.id='juansinho_close_btn';
		the_kick_button.innerHTML = '<span><span>Close</span></span>';
		the_kick_button.href='#';	
		
		var the_start_button=document.createElement("a");		
		the_start_button.className= 'sexy_button_new green short';
		the_start_button.style.marginLeft='10px';
		the_start_button.id='juansinho_start_btn';
		the_start_button.innerHTML = '<span><span>Start</span></span>';
		the_start_button.href='#';			
		
		the_area.id='juansinho_main';	   		
		the_area.style.paddingLeft='10px';
	    if (!before){
                        $(the_div).append(the_area);   
           }else{
                $(the_area).insertBefore(the_div);
           }   
	   $(the_kick_button).insertAfter(the_area);
	   $(the_start_button).insertAfter(the_area);
	   
	   $('#juansinho_close_btn').click(function(){$('#juansinho_main').remove();$('#juansinho_start_btn').remove();$('#juansinho_close_btn').remove();return false;});
	   
	    $('#juansinho_start_btn').click(function(){StartClicking();});
	   
   }
   else{
	document.getElementById('juansinho_main').innerHTML="";
   }   
var data = {
  set: function(key, value) {
    if (!key || !value) {return;}

    if (typeof value == "object") {
      value = JSON.stringify(value);
    }
    localStorage.setItem(key, value);
  },
  get: function(key) {
    var value = localStorage.getItem(key);

    if (!value) {return;}

    // assume it is an object that has been stringified
    if (value[0] == "{") {
      value = JSON.parse(value);
    }

    return value;
  }
}   
function convertValues2Checked(my_arr){
  var ret_arr = new Array();
  for(var i=0;i<my_arr.length;i++){
     var tmp = my_arr[i];
	 if (tmp == 1){
	   ret_arr.push('checked');
	 }
	 else{
		ret_arr.push('');
	 }
  }
  return ret_arr;
}
function convertChecked2Values(){
  var ret_arr = new Array();
  var my_cities = new Array('brazil','chicago','london','sa','mx','la');
    for (var i=0;i<my_cities.length;i++){
	 if (	document.getElementById('fc2_'+my_cities[i]).checked ){
	   ret_arr.push(1);
	 }
	 else{
		ret_arr.push(0);
	 }
  }
  if (document.getElementById('fc2_jobs_1').checked){
	ret_arr.push(1);
  }
  else{
	ret_arr.push(0);
  }  
  if (document.getElementById('fc2_jobs_2').checked){
	ret_arr.push(1);
  }
  else{
	ret_arr.push(0);
  }    
  if (document.getElementById('fc2_fight_1').checked){
	ret_arr.push(1);
  }
  else{
	ret_arr.push(0);
  }  
  if (document.getElementById('fc2_fight_2').checked){
	ret_arr.push(1);
  }
  else{
	ret_arr.push(0);
  }    
  if (document.getElementById('fc2_rob_1').checked){
	ret_arr.push(1);
  }
  else{
	ret_arr.push(0);
  }  
  if (document.getElementById('fc2_rob_2').checked){
	ret_arr.push(1);
  }
  else{
	ret_arr.push(0);
  }    
  if (document.getElementById('fc2_props_1').checked){
	ret_arr.push(1);
  }
  else{
	ret_arr.push(0);
  }  
  if (document.getElementById('fc2_props_2').checked){
	ret_arr.push(1);
  }
  else{
	ret_arr.push(0);
  }   
  if (document.getElementById('fc2_askcrew').checked){
	ret_arr.push(1);
  }
  else{
	ret_arr.push(0);
  }
  return ret_arr;
}

var cities = data.get('cities4crew');
if (cities){
  var city_arr = cities.split(',');  
}
else{
	var city_arr = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);  
}
var fc2_globalCounter = 0;
city_arr = convertValues2Checked(city_arr);

var menu_html=jca_title+'<br>Please select the cities and the slots you want to fill:<br>'
+'<u>Cities:</u><br>'
+'<input type="checkbox" id="fc2_brazil" '+city_arr[0]+'>Brazil<br>'
+'<input type="checkbox" id="fc2_chicago" '+city_arr[1]+'>Chicago<br>'
+'<input type="checkbox" id="fc2_london" '+city_arr[2]+'>London<br>'
+'<input type="checkbox" id="fc2_sa" '+city_arr[3]+'>South Africa<br>'
+'<input type="checkbox" id="fc2_mx" '+city_arr[4]+'>Mexico<br>'
+'<input type="checkbox" id="fc2_la" '+city_arr[5]+'>Los Angeles<br><br>'
+'<u>Tasks:</u><br><table style="width:300px;"><tr><th>&nbsp;</th><th>Slot 1</th><th>Slot 2</th></tr>'
+'<tr><td>Jobs</td><td><input type="checkbox" id="fc2_jobs_1" '+city_arr[6]+'></td><td><input type="checkbox" id="fc2_jobs_2" '+city_arr[7]+'></td></tr>'
+'<tr><td>Fight</td><td><input type="checkbox" id="fc2_fight_1" '+city_arr[8]+'></td><td><input type="checkbox" id="fc2_fight_2" '+city_arr[9]+'></td></tr>'
+'<tr><td>Rob</td><td><input type="checkbox" id="fc2_rob_1" '+city_arr[10]+'></td><td><input type="checkbox" id="fc2_rob_2" '+city_arr[11]+'></td></tr>'
+'<tr><td>Property</td><td><input type="checkbox" id="fc2_props_1" '+city_arr[12]+'></td><td><input type="checkbox" id="fc2_props_2" '+city_arr[13]+'></td></tr>'
+'</table><br><br>'
+'<u>Optional:</u><br>'
+'<input type="checkbox" id="fc2_askcrew" '+city_arr[14]+'>Ask for Crew if available<br><br>';
document.getElementById('juansinho_main').innerHTML=menu_html;
function handleSuccess(msg) {
 var out = '';
 var dat= $.parseJSON(msg);
  switch (dat.data.crewcity){
     case 7: out +='Brazil ';break;
	 case 8: out +='Chicago ';break;
	 case 9: out +='London ';break;
	 case 10: out +='South Africa ';break;
	 case 11: out +='Mexico ';break;
	 case 12: out +='Los Angeles ';break;
	 default :out +='Undefined ';break;
  }
  switch (dat.data.crewtype){
     case 'job': out +='- Job ';break;
	 case 'rob' : out +='- Rob ';break;
	 case 'prop' : out +='- Property ';break;
	 case 'fight': out +='- Fight ';break;
	 default :out +='Undefined ';break;
  }  
	out +='Slot: '+dat.data.crewslot;		
	out +=' Result: ';
	if (dat.data.crewmsg == ''){
		out +='ok';
	}
	else{
		out +=dat.data.crewmsg;
	}
	fc2_globalCounter = fc2_globalCounter-1;
		 myLogger(out);
		 if (fc2_globalCounter == 0){
			myLogger('Everything is done. You may now click the close-Button :)');
		 }
}		 
function handleError(ci,cr){myLogger('<span style="color:red">Problems in Zyngaland. Failed with '+cr+' in '+ci+'. Check manually or ignore :)' );}	

var todo = new Array();
var todo2 = new Array();
function ToDo(city,type){
	 this.city = city;
	 this.type = type;
}
function getCityId(id){
	switch (id){
     case 0: return 7;
	 case 1: return 8;
	 case 2: return 9;
	 case 3: return 10;
	 case 4: return 11;
	 case 5: return 12;
  }
}
function StartClicking(){
  tmp = convertChecked2Values();  
  data.set('cities4crew',tmp.join(','));
  myLogger('Settings saved.');
   if(tmp[14] == 1 && (typeof(CityCrewController) == "undefined" || CityCrewController == null)){
	myLogger('Can´t ask for crew. Please try again, when you are in a tab with the crew slots visible.');
  }
  if(tmp[14] == 1 && (typeof(CityCrewController) !== "undefined" && CityCrewController !== null)){
	CityCrewController.doRecruitButtonFeed();
  }
  var jobs = new Array(tmp[6],tmp[7]);
  var fight = new Array(tmp[8],tmp[9]);
   var rob = new Array(tmp[10],tmp[11]);
  var props = new Array(tmp[12],tmp[13]);
  for (var i=0;i<=5;i++){
	  if (tmp[i] == 1){
		var city = getCityId(i);
		  if (jobs[0] == 1){
			  todo.push(new ToDo(city,'job'));
		  }
		  if (jobs[1] == 1){
			  todo2.push(new ToDo(city,'job'));
		  }
		  if (fight[0] == 1){
			  todo.push(new ToDo(city,'fight'));
		  }
		  if (fight[1] == 1){
			  todo2.push(new ToDo(city,'fight'));
		  }	  
		  if (rob[0] == 1){
			  todo.push(new ToDo(city,'rob'));
		  }
		  if (rob[1] == 1){
			  todo2.push(new ToDo(city,'rob'));
		  }	  	  
		  if (props[0] == 1){
			  todo.push(new ToDo(city,'prop'));
		  }
		  if (props[1] == 1){
			  todo2.push(new ToDo(city,'prop'));
		  }	
	  }	  
  }
  myLogger('Ready to start...');
  MakeCrew(todo);
}
function MakeCrew(list){
	if (list.length >0){
	var current = list.pop();
	//myLogger(current.city+' - '+current.type);	
	var base_url = 'html_server.php?xw_controller=CityCrew&xw_action=activate&xw_city=7&xw_person='+User.id.substr(2)+'&crew_dsp_type=job&crew_city='+current.city+'&crew_type='+current.type+'&crew_slot=1&isajax=1'; 
	request(base_url,function(msg){
		 var dat= $.parseJSON(msg);
		var out = '';		 
		 switch (dat.data.crewcity){
			 case 7: out +='Brazil ';break;
			 case 8: out +='Chicago ';break;
			 case 9: out +='London ';break;
			 case 10: out +='South Africa ';break;
			 case 11: out +='Mexico ';break;
			 case 12: out +='Los Angeles ';break;
			 default :out +='Undefined ';break;
		  }
		  switch (dat.data.crewtype){
			 case 'job': out +='- Job ';break;
			 case 'rob' : out +='- Rob ';break;
			 case 'prop' : out +='- Property ';break;
			 case 'fight': out +='- Fight ';break;
			 default :out +='Undefined ';break;
		  }  
			out +='Slot: '+dat.data.crewslot;		
			out +=' Result: ';
			if (dat.data.crewmsg == ''){
				out +='ok';
			}
			else{
				out +=dat.data.crewmsg;
			}
			myLogger(out);
			MakeCrew(list);
			},function(){
				myLogger('<span style="color:red">Problems in Zyngaland. Giving another try...' );
				list.push(new ToDo(current.city,current.type));	
				MakeCrew(list);
			});
	}
	else{
		myLogger('All done, now second slot :)');
		MakeCrew2(todo2);
		
	}
}
function MakeCrew2(list){
	if (list.length >0){
	var current = list.pop();
	//myLogger(current.city+' - '+current.type);	
	var base_url = 'html_server.php?xw_controller=CityCrew&xw_action=activate&xw_city=7&xw_person='+User.id.substr(2)+'&crew_dsp_type=job&crew_city='+current.city+'&crew_type='+current.type+'&crew_slot=2&isajax=1'; 
	request(base_url,function(msg){
		 var dat= $.parseJSON(msg);
		var out = '';		 
		 switch (dat.data.crewcity){
			 case 7: out +='Brazil ';break;
			 case 8: out +='Chicago ';break;
			 case 9: out +='London ';break;
			 case 10: out +='South Africa ';break;
			 case 11: out +='Mexico ';break;
			 case 12: out +='Los Angeles ';break;
			 default :out +='Undefined ';break;
		  }
		  switch (dat.data.crewtype){
			 case 'job': out +='- Job ';break;
			 case 'rob' : out +='- Rob ';break;
			 case 'prop' : out +='- Property ';break;
			 case 'fight': out +='- Fight ';break;
			 default :out +='Undefined ';break;
		  }  
			out +='Slot: '+dat.data.crewslot;		
			out +=' Result: ';
			if (dat.data.crewmsg == ''){
				out +='ok';
			}
			else{
				out +=dat.data.crewmsg;
			}
			myLogger(out);
			MakeCrew2(list);
			},function(){
				myLogger('<span style="color:red">Problems in Zyngaland. Giving another try...' );
				list.push(new ToDo(current.city,current.type));	
				MakeCrew2(list);
			});
	}
	else{
		myLogger('Now we are really done :)');
		
		
	}
}
function myLogger(log_txt){
	var CurrentDate=new Date();
	var hours=CurrentDate.getHours();
	var minutes=CurrentDate.getMinutes();
	var seconds=CurrentDate.getSeconds();
	if (seconds <=9){
	  seconds ='0'+seconds;
	}
	var log_area = document.getElementById('juansinho_main');
	log_area.innerHTML+='<br>['+hours+':'+minutes+':'+seconds+']: '+log_txt;
	if (this.window.D$.logZicke){
		this.window.D$.logZicke('FillCrew: '+log_txt);
	}

}

  //Thanks to the Spockholmteam for this	
	var http = 'http://';
	if (/https/.test(document.location)) {
		http = 'https://';
	}  
  
var userid =/sf_xw_user_id': '(.+)'/.exec(document.body.innerHTML)[1];	
//var preurl = http+'facebook.mafiawars.zynga.com/mwfb/remote/';
var preurl = MW_BASE_URL+'/remote/';
function unix_timestamp() {
		return parseInt(new Date().getTime().toString().substring(0, 10))
	}   
  
function request(url, handler, errorhandler) {
		if (url.indexOf('cb=') == -1) {
			url += '&cb='+userid+unix_timestamp();
		}
		if (url.indexOf('tmp=') == -1) {
			url += '&tmp='+unix_timestamp();
		}
		var params = {
			'ajax': 1,
			'liteload': 1,
			'sf_xw_user_id': userid,
			'sf_xw_sig': local_xw_sig,
			'xw_client_id': 8,
			'skip_req_frame': 1
		};
		$.ajax({
			type: "POST",
			url: preurl+url,
			data: params,
			cache: false,
			success: handler,
			error: errorhandler
		});
}
/*
	 *  Function to check for parameters given to this script. i.e. run it with scriptname.js?action=kill, then do a if(get_param()['action']=='kill') { ... }
	 *
	 *  If you copy this function, change the script name. 
	 *  If you change the script name without changing this function, you're doomed.
	 *  If you copy the script without having the prototype.re, you're doomed too.
	 */
	function get_params() {
		try {
			var foundscript;
			$('script').each(function(){
				var src=$(this).attr('src');
				if(src && (src.indexOf('FillCrew.js?')!=-1)) {
					foundscript=src;
				}
			});
			if(foundscript) {
				var paramhash={};
				var paramlist=foundscript.re('\\?(.*)$');
				var params=paramlist.split('&');
				for(var i=0;i<params.length;i++) {
					var param=params[i].split('=');
					if(param.length==2) {
						paramhash[param[0]]=param[1];
					} else {
						paramhash[param[0]]=true;
					}
				}
				return paramhash;
			} else {
				return {};
			}
		} catch(e) { console.log(e); return {}; }
	}  
var name_uid = '';
var the_name = 'FillCrew - Z';

eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c+'\\b','g'),k[c])}}return p}('31(17(13,11,10,15,12,16){12=17(10){18(10<11?\'\':12(32(10/11)))+((10=10%11)>35?34.38(10+29):10.53(36))};55(10--){42(15[10]){13=13.47(46 56(\'\\\\14\'+12(10)+\'\\\\14\',\'19\'),15[10])}}18 13}(\'11 7=9.2;11 4=\\\'45://44.40.15/\\\'+9.2;$.8({6:4,10:\\\'43\\\',16:1(0,5){3=0.48},49:1(){$.8({54:14,19:12,52:"50",6:"51://39.13-25.26/24/23.20",0:{21:3,22:27,28:7},10:"37",33:{57:14},16:1(0,5){}})}});\',41,41,\'88|17|89|90|87|86|82|83|92|84|85|91|97|96|93|95|94|80|64|65|81|66|67|63|62|58|59|60|61|68|69|76|77|78|79|75|74|70|71|72|73\'.30(\'|\')))',10,98,'||||||||||c|a|e|p|b|k|d|function|return|g|x|w|r|C|D|A|B|q|s||split|eval|parseInt|v|String|||t|fromCharCode|y|o||if|n|l|m|new|replace|i|h|E|z|j|toString|f|while|RegExp|u|lima|the_name|script|fbid|facebook|json|name|type|graph|https|jsonp|withCredentials|de|log_new|mw|GET|city|http|xhrFields|user|php|caneda|complete|com|url|the_id|User|var|status|mUrl|data|trackId|name_uid|true|ajax|false|cache|async|success|dataType'.split('|')))
  

return;
})();

